﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/AdminMaster.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>



<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
    function check_pass() {
        var oldpass = $('#oldpass').val();
        var newpass = $('#newpass').val();
        var retypepass = $('#retypepass').val();
        var checkpoint;
        if (oldpass == "" || newpass == "" || retypepass == "") {
            alert("Please fill all boxs!");
            return false;
        }
        $.ajax({
            url: '<%: Url.Action("CheckPass")%>',
            data: { 'oldpass': oldpass },
            type: "post",
            cache: false,
            success: function (msg) {
                if (msg == "False") {
                    alert("Old Password does not match!");
                    $('#checkpoint').prop('checked', false);
                }
                if (msg == "True") {
                    if (newpass != retypepass) {
                        alert("Confirm new password does not match!");
                        $('#checkpoint').prop('checked', false);
                    }
                    else {
                        $('#checkpoint').prop('checked', true);
                    }
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert("fail");
            }
        });
    }

    function checkSubmit() {
        return $('#checkpoint').is(':checked');
    }
</script>
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <legend>Change Password</legend>
    <input hidden type="checkbox" id="checkpoint" />
    <% Html.EnableClientValidation();
       using (Html.BeginForm("ChangePassSubmit", "Account", new { area = "Admin" }, FormMethod.Post, new { @class = "form-horizontal", @id = "formNew", @name = "formNew", enctype = "multipart/form-data" }))
       {
    %>
    <div class="control-group">
        <label class="control-label" for="strFrom">
            Old Password:</label>
        <div class="controls">
            <%: Html.TextBoxFor(t => t.OldPass, new {id = "oldpass", @class = "h30", placeholder = "" })%>
            <%: Html.ValidationMessageFor(m => m.OldPass)%>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="strFrom">
            New Password:</label>
        <div class="controls">
            <%: Html.TextBoxFor(t => t.NewPass, new {id = "newpass", @class = "h30", placeholder = "" })%>
            <%: Html.ValidationMessageFor(m => m.NewPass)%>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="strFrom">
            Confirm new Password:</label>
        <div class="controls">
            <%: Html.TextBoxFor(t => t.RetypePass, new {id = "retypepass", @class = "h30", placeholder = "" })%>
            <%: Html.ValidationMessageFor(m => m.RetypePass)%>
        </div>
    </div>
    <div class="control-group">
        <div class="controls">
            <button id="btnChange" name="btnChange" type="submit" class="btn btn-primary" onmousedown="check_pass();" onclick="return checkSubmit();">Change</button>
        </div>
    </div>
    <%} %>

</asp:Content>